
FREE_ANGLE=181
SERVO_NUM = 80
ADRESS_TABLE = []
from socket import *

HOST = '192.168.1.111' # or 'localhost'
PORT = 5050
ADDR = (HOST,PORT)
 
class rmt_ctl():
    def __init__(self, num = SERVO_NUM, address = ADRESS_TABLE):
        self.tcpCliSock = socket(AF_INET,SOCK_STREAM)
        self.tcpCliSock.connect(ADDR)

    def _run_to(self, idx, angle):
        ctlStr = "servoCtl.set_angle({}, {}, {}, {})\n".format(idx, angle, speed, True)
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

####################################################
    def set_angle(self, idx, angle, speed = 0, update = False):
        ctlStr = "servoCtl.set_angle({}, {}, {}, {})\n".format(idx, angle, speed, update)
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

    def play_note(self, note, update = False):
        ctlStr = "servoCtl.set_angle({}, {}, {}, {})\n".format(idx, angle, speed, update)
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

    def update(self):
        ctlStr = "servoCtl.update()\n"
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

####################################################
    def systemHelp(self, cmd):
        ctlStr = "os.system(\"{}\")\n".format(cmd)
        self.tcpCliSock.send(bytes(ctlStr, "utf8"))

    def playMidi(self, path):
        self.systemHelp("python3 ~/Desktop/autoBand/tools/midi_parse/midi_play.py -f {}".format(path))

    def pauseMidi(self):
        pass

    def stopMidi(self):
        pass


rmtCtl = rmt_ctl()

rmtCtl.playMidi("~/Desktop/autoBand/source/midi/myMidi/midiShow/钟.mid")